package com.boot.webflux.security.example2.handler;

import com.boot.webflux.security.example2.utils.RespUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.ReactiveSecurityContextHolder;
import org.springframework.security.web.server.WebFilterExchange;
import org.springframework.security.web.server.authentication.logout.ServerLogoutSuccessHandler;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;

import java.util.HashMap;
import java.util.Map;

/**
 * 退出成功后处理类
 */
@Component
@Slf4j
public class CloudLogoutSuccessHandler  implements ServerLogoutSuccessHandler {
    @Override
    public Mono<Void> onLogoutSuccess(WebFilterExchange webFilterExchange, Authentication authentication)  {
        ServerHttpResponse response = webFilterExchange.getExchange().getResponse();
        Map<String,Object> resultData = new HashMap<>();
        resultData.put("code","200");
        resultData.put("msg", "登出成功");
        ReactiveSecurityContextHolder.clearContext();
        return RespUtil.writeMsg(response,200,resultData);
    }
}
